package com.qf.service.impl;

import com.qf.constant.CacheConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.Strategy;
import com.qf.service.api.CacheService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 黑名单策略
 * @author 何星宇
 * @version V1.0
 * @Date 2021/11/23 19:28
 */

@Service(value = "black")
@Slf4j
public class BlackStrategy implements Strategy {
    @Autowired
    private CacheService cacheService;
    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        //记录日志
        log.info("【策略模块-黑名单策略】 策略开始执行！");
        //获取黑名单电话信息
        String blackPhone = cacheService.get(CacheConstants.CACHE_PREFIX_BLACK + standardSubmit.getClientID());

        if (!StringUtils.isEmpty(blackPhone)){
            //黑名单中存在该电话
            log.info("【策略模块-黑名单策略】 目的手机号在黑名单存在！ standardSubmit={}",standardSubmit);
            return false;
        }
        return true;
    }
}
